Operator_Subtract Method

Used to overload the - operator when used for subtraction, providing custom functionality.

Syntax


Notes

Create an Operator_Subtract function in a class to specify the functionality of the - operator for that class.

In the function, the Self instance is the left operand and the other operand is passed as a parameter.


Example

Suppose you have a class, Vector, that can store a vector. To define the - operator for this class, create a method of the Vector class called Operator_Subtract.

The Vector class has two Integer properties, x and y.

Operator_Subtract is defined as:

Function Operator_Subtract (rhs as Vector) as Vector
 //rhs stands for right-hand-side, the vector to be added to Self
  Dim ret as New Vector   //the differenct between the two vectors
 ret.x= Self.x - rhs.x
 ret.y= Self.y - rhs.y

Return ret

See Also

- operator, Operator_SubtractRight function.